import { useContext } from 'react';
import ConfigProviderContext, { INITIAL_STATE } from '../config-provider/ConfigProviderContext';
import { createNamespace as createNamespaceUtil } from './create';
import type { CreateNamespaceReturn } from './create';

export function useNamespace(component: string): CreateNamespaceReturn {
  const { prefixCls = INITIAL_STATE.prefixCls, createNamespace = INITIAL_STATE.createNamespace } =
    useContext(ConfigProviderContext);

  return (createNamespace || createNamespaceUtil)(component, prefixCls);
}

export default useNamespace;
